package com.cmf.myproject.controller.boss.project;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cmf.myproject.dal.mybatis.model.Project;
import com.cmf.myproject.service.project.dto.ProjectAddItemReqDto;
import com.cmf.myproject.service.project.dto.ProjectUpdateItemReqDto;
import com.cmf.myproject.service.project.ProjectService;
import com.cmf.myproject.service.project.dto.ProjectQueryFilter;
import com.system.core.controller.ControllerBase;
import com.system.core.results.ResultBase;
import com.system.core.view.layui.table.TableViewRspDto;

@Controller
@RequestMapping("boss/project")
public class ProjectController extends ControllerBase {
	@Autowired
	private ProjectService projectService;
	
	@RequiresPermissions("project_topage")
	@RequestMapping(value = "to_page",method = RequestMethod.GET)
	public String toPage() {
		getModelMap().put("projectOwnerTypeEnum", com.cmf.myproject.dal.mybatis.enums.ProjectOwnerTypeEnum.getAllEnum());
		return "/boss/project/project-list";
	}
	
	@RequestMapping(value = "query_list",method = RequestMethod.POST)
	@ResponseBody
	public TableViewRspDto<Project> projectQueryList(ProjectQueryFilter filter) {
		TableViewRspDto<Project> rsp = projectService.projectList(filter);
		return rsp;
	}
	
	@RequestMapping(value = "get_item_by_key",method = RequestMethod.POST)
	@ResponseBody
	public Project projectGetByPrimaryKey(Project project){
		return projectService.projectGetByPrimaryKey(project);
	}
	
	@RequiresPermissions("project_add_opt")
	@RequestMapping(value = "add_item",method = RequestMethod.POST)
	@ResponseBody
	public ResultBase projectAddItem(@Validated ProjectAddItemReqDto projectAddItemReqDto) {
		return projectService.projectSave(projectAddItemReqDto);
	}
	
	@RequiresPermissions("project_edit_opt")
	@RequestMapping(value = "update_item",method = RequestMethod.POST)
	@ResponseBody
	public ResultBase projectUpdateItem(@Validated ProjectUpdateItemReqDto projectUpdateItemReqDto) {
		return projectService.projectUpdateByPrimaryKey(projectUpdateItemReqDto);
	}
	
	@RequiresPermissions("project_delete_opt")
	@RequestMapping(value = "delete_item",method = RequestMethod.POST)
	@ResponseBody
	public ResultBase projectDeleteItem(@RequestBody List<Long> keys) {
		return projectService.projectDeleteByPrimaryKey(keys);
	}
}
